/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.factories;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Extension;

import com.cea.papyrus.core.commands.association.AssociationCreateCommand;
import com.cea.papyrus.core.commands.connection.ConnectionCreateCommand;
import com.cea.papyrus.core.commands.connection.InstanceSpecificationLinkCreateCommand;
import com.cea.papyrus.core.pseudoelement.InstanceSpecificationLink;
import com.cea.papyrus.core.pseudoelement.UMLElementFactory;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Factory that creates ConnectionCreateCommand for edges.
 */
public class ConnectionCreateCommandFactory {
	
	/**
	 * Singleton instance of the factory.
	 */
	public static ConnectionCreateCommandFactory eINSTANCE = new ConnectionCreateCommandFactory();

	/**
	 * @TODO is this variable needed ? 
	 */
	protected java.lang.Class type;
	/**
	 * Creates a ConnectionCreateCommand for the given parameters.
	 * 
	 * @param type 
	 * @param location 
	 * @param source 
	 * 
	 * @return 
	 */
	public ConnectionCreateCommand getConnectionCreateCommand(GraphElement source, Object newObjectDescription, Point location) {
		if (newObjectDescription instanceof UMLElementFactory) {
			UMLElementFactory enhancedType = (UMLElementFactory) newObjectDescription;
			type          = enhancedType.getClazz();
			
		} else {
			type = (Class)  newObjectDescription;
		}
		java.lang.Class eClass = (java.lang.Class)type;
		if(eClass.equals(Extension.class)){
			return new com.cea.papyrus.core.commands.extension.ExtensionCreateCommand(source, newObjectDescription,location);}
		if(eClass.equals(Association.class)){
			return new AssociationCreateCommand(source, newObjectDescription,location);}
		if(eClass.equals(InstanceSpecificationLink.class)){
			return new  InstanceSpecificationLinkCreateCommand(source, newObjectDescription,location);}

		return new ConnectionCreateCommand(source, newObjectDescription,location);

	}
	
	
}	
